import REGEX from 'config/regexConfig'
import * as pwdS from 'plus/pwdStrength'

const MSGTYPE = {
  ISOK:0,
  ISNULL:1,
  ISERROR:2,
  ISOUT:3
}

const isStandardCode = (($) => {
  const $code = () => {}
  $code.isPhone = (val) => {
      if(val.trim()){
          if(REGEX.PhONE_REG.CODE.test(val)){
            return {
              code: MSGTYPE.ISOK
            }
          }else{
            return {
              code: MSGTYPE.ISERROR,
              msg: "请填写正确的手机号"
            }
          }
      }else{
        return {
          code: MSGTYPE.ISNULL,
          msg: "手机号不能为空"
        }
      }
  }
  $code.verifyAccount = (val) => {
    if(val.trim() !== ''){
      if(val.length < 8){
        return {
          code: MSGTYPE.ISNULL,
          msg: "密码长度为8-20位"
        }
      }else {
        if(pwdS.pwStrength(val)){
          return {
            code: MSGTYPE.ISNULL,
            msg:pwdS.pwStrength(val)
          }
        }return {
          code: MSGTYPE.ISOK
        }

      }
    }else {
      return {
        code: MSGTYPE.ISNULL,
        msg: "请输入密码"
      }
    }
  }
  return $code
})(document)

export default isStandardCode
